@extends('layout')
@section('head')
    @parent
@stop
@section('content')
    <div class="register_header">欢迎加入豆辨</div>
    <form id="form" method="post">
    <div class="register_input">
        <div class="register_item">
            <label>邮箱</label><input class="register_item_input" id="email" name="email">
            <div class="register_prompt">
                <img class="prompt_right" id="img_email" src="{{URL::asset('assets/img/right.gif')}}" hidden>
                <span id="span_email" class="prompt_wrong"></span>
            </div>
        </div>
        <div class="register_item">
            <label>密码</label><input type="password" class="register_item_input" id="password" name="password">
            <div class="register_prompt">
                <img class="prompt_right" id="img_password" src="{{URL::asset('assets/img/right.gif')}}" hidden>
                <span id="span_password" class="prompt_wrong"></span>
            </div>
        </div>
        <div class="register_item">
            <label>确认密码</label><input type="password" class="register_item_input" id="confirm" name="confirm">
            <div class="register_prompt">
                <img class="prompt_right" id="img_confirm" src="{{URL::asset('assets/img/right.gif')}}" hidden>
                <span id="span_confirm" class="prompt_wrong"></span>
            </div>
        </div>
        <div class="register_item">
            <label>昵称</label><input class="register_item_input" id="nickname" name="nickname">
            <div class="register_prompt">
                <img class="prompt_right" id="img_nickname" src="{{URL::asset('assets/img/right.gif')}}" hidden>
                <span id="span_nickname" class="prompt_wrong"></span>
            </div>
        </div>
        <div class="nickname_suggestion">第一印象很重要，起个文雅又响亮的昵称吧</div>
        <div class="register_item">
            <label>性别</label>
            <span class="register_radio"><input type="radio" name="sex" value="保密">&nbsp;&nbsp;&nbsp;保密</span>
            <span class="register_radio"><input type="radio" name="sex" value="男">&nbsp;&nbsp;&nbsp;男</span>
            <span class="register_radio"><input type="radio" name="sex" value="女">&nbsp;&nbsp;&nbsp;女</span>
        </div>
        <input type="button" id="regis" class="register_button_d" value="注册" onclick="register()">
    </div>
    </form>
    <script>
        $(function () {
            var email=$("#email");
            email.blur(function () {
                if(email.val().length==0){
                    $("#img_email").hide();
                    $("#span_email").show();
                    $("#span_email").html("输入不能为空");
                }
                else if(email.val().length>30){
                    $("#img_email").hide();
                    $("#span_email").show();
                    $("#span_email").html("你输那么长干嘛");
                }
                else {
                $.post("{{url('check')}}",
                    {
                        email:email.val()
                    },
                    function (data) {
                        if(data=="right"){
                            $("#img_email").show();
                            $("#span_email").hide();
                        }
                        else{
                            $("#span_email").html(data);
                            $("#img_email").hide();
                            $("#span_email").show();
                        }
                    });
                }
            });

            var password=$("#password");
            password.blur(function () {
                if(password.val().length==0){
                    $("#img_password").hide();
                    $("#span_password").show();
                    $("#span_password").html("输入不能为空");
                }
                else if(password.val().length>30){
                    $("#img_password").hide();
                    $("#span_password").show();
                    $("#span_password").html("你输那么长干嘛");
                }
                else if(password.val().indexOf(" ")!=-1){
                    $("#img_password").hide();
                    $("#span_password").show();
                    $("#span_password").html("密码不能包含空格");
                }
                else if(password.val().length<6){
                    $("#img_password").hide();
                    $("#span_password").show();
                    $("#span_password").html("密码过短");
                }
                else{
                    $("#span_password").hide();
                    $("#img_password").show();
                }

            });

            var confirm=$("#confirm");
            confirm.blur(function () {
                if(confirm.val().length==0){
                    $("#img_confirm").hide();
                    $("#span_confirm").show();
                    $("#span_confirm").html("输入不能为空");
                }else {
                    if(password.val()!=confirm.val()){
                        $("#img_confirm").hide();
                        $("#span_confirm").show();
                        $("#span_confirm").html("两次密码输入不一致");
                    }
                    else{
                        $("#span_confirm").hide();
                        $("#img_confirm").show();
                    }
                }
            });

            var nickname=$("#nickname");
            nickname.blur(function () {
                if(nickname.val().length==0){
                    $("#img_nickname").hide();
                    $("#span_nickname").show();
                    $("#span_nickname").html("输入不能为空");
                }
                else if(nickname.val().length>30){
                    $("#img_nickname").hide();
                    $("#span_nickname").show();
                    $("#span_nickname").html("你输那么长干嘛");
                }
                else if(nickname.val().length<2){
                    $("#img_nickname").hide();
                    $("#span_nickname").show();
                    $("#span_nickname").html("名号过短，不够响亮");
                }
                else {
                    $.post("{{url('check')}}",
                        {
                            nickname:nickname.val()
                        },
                        function (data) {
                            if(data=="right"){
                                $("#span_nickname").hide();
                                $("#img_nickname").show();
                            }
                            else{
                                $("#span_nickname").html(data);
                                $("#img_nickname").hide();
                                $("#span_nickname").show();
                            }
                        });
                    }
            });

            $("input[name='sex']").click(function () {
                    $("#regis").attr("class", "register_button");

            });
        });
        function register() {
            if($("#img_email").is(":hidden")==false&&$("#img_password").is(":hidden")==false&&$("#img_confirm").is(":hidden")==false&&$("#img_nickname").is(":hidden")==false){
                $.post("{{url('addUser')}}",
                {
                    email:$('#email').val(),
                    password:$('#password').val(),
                    nickname:$('#nickname').val(),
                    sex:$("input:radio:checked").val()
                },
                function (data) {
                    alert(data);
                    window.location.href = document.referrer;
                });
            }
            else {
                alert('输入有误');
            }

        }
        function test() {
            document.getElementById("form").submit();
        }
    </script>
    @stop

@section('foot')

@stop